#include <iostream>
#include <algorithm>

using namespace std;

int list[14];
bool add[32] = { false };
bool sub[32] = { false };
bool used[14] = { false };
int result = 0;
int n;
void dfs(int depth)
{
    int i, j;
    // cout << depth << ' ';
    if (depth > n)
    {   
        result++;
        if (result <= 3)
        {
            for (i = 1; i <= n; i++)
            {
                if (i > 1) cout << " ";
                cout << list[i];           
            }
            cout << "\n";
        }
        return;
    }

    for (i = 1; i <= n; i++)
    {
        if (used[i] || add[i + depth] || sub[depth - i + n])
        {
            continue;
        }
        
        list[depth] = i;
        used[i] = true;
        add[depth + i] = true;
        sub[depth - i + n] = true;
        dfs(depth + 1);
        used[i] = false;
        add[depth + i] = false;
        sub[depth - i + n] = false;
    }
}

int main(int argc, char const *argv[])
{
    cin >> n;
    dfs(1);
    cout << result;
    return 0;
}
